<template>
  <el-select
    style="width: 240px"
    size="small"
    v-model="value"
    :placeholder="placeholder"
    @change="selectItem"
    :clearSelect="clearSelect"
    :disabled="disabled"
    :loading="loading"
    :loading-text="loadingText"
  >
    <el-option
      v-for="item in options"
      :key="item.dictValue"
      :label="item.dictLabel"
      :value="item.dictValue"
    ></el-option>
  </el-select>
</template>

<script>
export default {
  name: "slShop",
  data() {
    return {
      value: "",
      options: [],
    };
  },
  props: {
    defaultValue: [String, Number, Object], //默认值
    code: [String, Number],
    clearSelect: [Boolean, String], //清空select
    tag: {
      type: [String, Number],
      default: "",
    },
    index: {
      type: [String, Number],
      default: "",
    },
    placeholder: {
      type: String,
      default: "请选择",
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    clearable: {
      type: Boolean,
      default: true,
    },
    loading: {
      type: Boolean,
      default: false,
    },
    loadingText: {
      type: String,
      default: "加载中",
    },
  },
  watch: {
    defaultValue(val) {
      //监听默认值改变
      this.value = val;
    },
    clearSelect: {
      //深度监听，可监听到对象、数组的变化
      handler(newV) {
        newV;
        if (newV) {
          this.value = "";
          this.$emit("clearSelectState", false);
        }
      },
      deep: true,
    },
  },
  created() {
    this.getActivityImg()
  },
  methods: {
    //获取活动图片类型
    getActivityImg() {
      this.getDicts(this.code).then((response) => {
        var imgtype = response.data
        this.options = imgtype;
      });
    },

    selectItem: function (e,typeNmae) {
      console.log("xin-zeng")
      let filterArr = [],
        name = "";
      filterArr = this.options.filter((item, index) => {
        return e === item.dictValue;
      });
      console.log('dddd',filterArr[0])
      //  filterArr = this.options.filter((item, index) => {
      //   return nameDictLabel =item.dictLabel;
      // });
      if (filterArr.length > 0) {
        name = filterArr[0].dictName || "";
      }
      this.$emit("getSelectResult", e,filterArr[0]);
    },
    // fetchlocal(code) {
    //   return new Promise(function (resolve, reject) {
    //     var data = JSON.parse(sessionStorage.getItem(code));
    //     // console.log("内存中uum",data);
    //     if (data == "" || data == null || data == "undefined") {
    //       reject({
    //         code: code,
    //         data: null,
    //         status: 404,
    //       });
    //     } else {
    //       resolve(data);
    //     }
    //   });
    // },
    // fetchUum(type, callback) {
    //   let url = this.$uumHost + type + "&tag=" + this.tag;
    //   this.$axios(url)
    //     .then((res) => {
    //       if (res.data.success) {
    //         callback(res.data);
    //       } else {
    //         this.$message({
    //           message: "数据获取失败",
    //           type: "error",
    //         });
    //       }
    //     })
    //     .catch((err) => {
    //       this.$message({
    //         message: "获取数据失败",
    //         type: "error",
    //       });
    //     });
    // },
  },
};
</script>
<style>
</style>
